package fenetres;

import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import java.awt.Font;
import java.awt.Toolkit;
import javax.swing.JTextField;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.JButton;
import javax.swing.JPasswordField;

public class FenConnexion extends JFrame {

	private JPanel contentPane;
	private JLabel jLab_Ordinateur;
	private JLabel jLab_Cadre;
	private JLabel jLab_Titre;
	private JTextField jTxT_Nom;
	private JLabel lblNewLabel;
	private JLabel lblMotDePasse;
	private JButton jBtn_Quitter;
	private JButton jBtn_Valider;
	private JLabel jLab_Param;
	private JPasswordField jTxT_MDP;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					FenConnexion frame = new FenConnexion();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public FenConnexion() {
		setIconImage(Toolkit.getDefaultToolkit().getImage(FenConnexion.class.getResource("/images/connection/logoEclipse.png")));
		setTitle("SWECOM GESTION");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		// Bouton ayant le focus par defaut
		getRootPane().setDefaultButton(jBtn_Valider); 
		setResizable(false);
		setBounds(100, 100, 450, 300);
		setLocationRelativeTo(null);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		contentPane.add(getJTxT_MDP());
		contentPane.add(getJTxT_Nom());
		contentPane.add(getLblMotDePasse());
		contentPane.add(getLblNewLabel());
		contentPane.add(getJLab_Ordinateur());
		contentPane.add(getJLab_Titre());
		contentPane.add(getJLab_Cadre());
		contentPane.add(getJBtn_Quitter());
		contentPane.add(getJBtn_Valider());
		contentPane.add(getJLab_Param());
	}
	private JLabel getJLab_Ordinateur() {
		if (jLab_Ordinateur == null) {
			jLab_Ordinateur = new JLabel("");
			jLab_Ordinateur.setIcon(new ImageIcon(FenConnexion.class.getResource("/images/connection/ecran.png")));
			jLab_Ordinateur.setBounds(10, 11, 64, 71);
		}
		return jLab_Ordinateur;
	}
	private JLabel getJLab_Cadre() {
		if (jLab_Cadre == null) {
			jLab_Cadre = new JLabel("");
			jLab_Cadre.setIcon(new ImageIcon(FenConnexion.class.getResource("/images/connection/ban.png")));
			jLab_Cadre.setBounds(30, 26, 380, 186);
		}
		return jLab_Cadre;
	}
	private JLabel getJLab_Titre() {
		if (jLab_Titre == null) {
			jLab_Titre = new JLabel("Connexion au Programme");
			jLab_Titre.setFont(new Font("Segoe UI", Font.PLAIN, 24));
			jLab_Titre.setBounds(84, 45, 302, 37);
		}
		return jLab_Titre;
	}
	private JTextField getJTxT_Nom() {
		if (jTxT_Nom == null) {
			jTxT_Nom = new JTextField();
			jTxT_Nom.setFont(new Font("Segoe UI", Font.PLAIN, 12));
			jTxT_Nom.setForeground(Color.BLACK);
			jTxT_Nom.setBounds(189, 121, 197, 30);
			jTxT_Nom.setForeground(new Color(26, 88, 131));
			jTxT_Nom.setColumns(10);
		}
		return jTxT_Nom;
	}
	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			lblNewLabel = new JLabel("Nom d'utilisateur");
			lblNewLabel.setIcon(new ImageIcon(FenConnexion.class.getResource("/images/connection/utilisateur.png")));
			lblNewLabel.setLabelFor(getJTxT_Nom());
			lblNewLabel.setBounds(67, 121, 118, 22);
		}
		return lblNewLabel;
	}
	private JLabel getLblMotDePasse() {
		if (lblMotDePasse == null) {
			lblMotDePasse = new JLabel("Mot de passe");
			lblMotDePasse.setIcon(new ImageIcon(FenConnexion.class.getResource("/images/connection/key.png")));
			lblMotDePasse.setBounds(67, 170, 112, 22);
		}
		return lblMotDePasse;
	}
	private JButton getJBtn_Quitter() {
		if (jBtn_Quitter == null) {
			jBtn_Quitter = new JButton("Quitter");
			jBtn_Quitter.setFont(new Font("Tahoma", Font.BOLD, 10));
			jBtn_Quitter.setIcon(new ImageIcon(FenConnexion.class.getResource("/images/connection/cancel.png")));
			jBtn_Quitter.setBounds(307, 223, 113, 30);
			jBtn_Quitter.addActionListener(new ActionListener(){
				public void actionPerformed(ActionEvent e){
					System.exit(0);
				}
			});
			jBtn_Quitter.addKeyListener(new KeyAdapter(){
				public void keyPressed(KeyEvent e){
					if(e.getKeyCode() == 10){
						System.exit(0);
					}
				}
			});
		}
		return jBtn_Quitter;
	}
	private JButton getJBtn_Valider() {
		if (jBtn_Valider == null) {
			jBtn_Valider = new JButton("Valider");
			jBtn_Valider.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					FenMenuPrincipal laFenetre = new FenMenuPrincipal();
					laFenetre.setVisible(true);
					dispose();
				}
			});
			jBtn_Valider.setFont(new Font("Tahoma", Font.BOLD, 10));
			jBtn_Valider.setIcon(new ImageIcon(FenConnexion.class.getResource("/images/connection/valider.png")));
			jBtn_Valider.setBounds(200, 223, 108, 30);
		}
		return jBtn_Valider;
	}
	private JLabel getJLab_Param() {
		if (jLab_Param == null) {
			jLab_Param = new JLabel("Param\u00E8tres de connexion");
			jLab_Param.setFont(new Font("Segoe UI", Font.PLAIN, 12));
			jLab_Param.setIcon(new ImageIcon(FenConnexion.class.getResource("/images/connection/switch-on.png")));
			jLab_Param.setBounds(10, 223, 175, 30);
			// Pour avoir le pointeur de la souris sous forme de main
			jLab_Param.setCursor(new Cursor(Cursor.HAND_CURSOR)); 
		}
		return jLab_Param;
	}
	private JPasswordField getJTxT_MDP() {
		if (jTxT_MDP == null) {
			jTxT_MDP = new JPasswordField();
			jTxT_MDP.setFont(new Font("Segoe UI", Font.PLAIN, 12));
			jTxT_MDP.setBounds(189, 162, 197, 30);
		}
		return jTxT_MDP;
	}
}
